import 'package:animal/constant/color.dart';
import 'package:animal/constant/font.dart';
import 'package:animal/ui/login/controller/pwd_login_controller.dart';
import 'package:animal/utils/screen_util.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:getwidget/getwidget.dart';

///密码登录
class PwdLoginPage extends StatelessWidget {
  const PwdLoginPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final controller = Get.put(PwdLoginController());
    return Scaffold(
        backgroundColor: Colors.white,
        resizeToAvoidBottomInset: false,
        body: SingleChildScrollView(
          physics: const NeverScrollableScrollPhysics(),
          child: Container(
              margin: EdgeInsets.only(left: ScreenUtil().L(30), right: ScreenUtil().L(30), top: ScreenUtil().L(30), bottom: ScreenUtil().L(10)),
              child: Column(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
                Column(
                  children: [
                    Row(
                      children: [
                        Text("使用密码登录", style: KFontConstant.myTextStyle(size: 20, bold: true, color: Colors.black)),
                      ],
                    ),
                    Container(height: ScreenUtil().L(10)),
                    Container(
                      decoration: BoxDecoration(border: Border(bottom: BorderSide(color: const Color(0XFFEEEEEE), width: ScreenUtil().L(0.5)))),
                      child: TextField(
                        controller: controller.phoneController,
                        maxLength: 11,
                        keyboardType: TextInputType.phone,
                        decoration: InputDecoration(
                            hintText: "请输入手机号码",
                            hintStyle: KFontConstant.myTextStyle(size: 15, color: const Color(0XFFBFC4CC)),
                            border: InputBorder.none,
                            suffixIcon: Obx(() {
                              return Visibility(
                                  visible: controller.showDeleteBtn.value,
                                  child: GFIconButton(
                                    type: GFButtonType.transparent,
                                    icon: const Icon(Icons.highlight_remove_rounded),
                                    onPressed: () => controller.clearPhoneNumber(),
                                  ));
                            }),
                            counterText: ""),
                        inputFormatters: [
                          FilteringTextInputFormatter.allow(RegExp(r'[0-9]')) //设置只允许输入数字
                        ],
                      ),
                    ),
                    Container(
                      margin: EdgeInsets.only(top: ScreenUtil().L(10)),
                      decoration: BoxDecoration(border: Border(bottom: BorderSide(color: const Color(0XFFEEEEEE), width: ScreenUtil().L(0.5)))),
                      child: Obx(() {
                        return TextField(
                          controller: controller.pwdController,
                          maxLength: 20,
                          obscureText: controller.obscure.value,
                          cursorRadius: Radius.circular(ScreenUtil().L(2)),
                          keyboardType: TextInputType.visiblePassword,
                          decoration: InputDecoration(
                              hintText: "请输入密码",
                              hintStyle: KFontConstant.myTextStyle(size: 15, color: const Color(0XFFBFC4CC)),
                              border: InputBorder.none,
                              suffixIcon: InkWell(
                                  onTap: () => controller.obscure.value = !controller.obscure.value,
                                  highlightColor: const Color(0x00FFFFFF),
                                  hoverColor: const Color(0x00FFFFFF),
                                  child: Obx(() {
                                    return GFIconButton(
                                      type: GFButtonType.transparent,
                                      icon: controller.obscure.value ? const Icon(Icons.visibility_off) : const Icon(Icons.visibility),
                                      onPressed: () => controller.obscure.value = !controller.obscure.value,
                                    );
                                  })),
                              counterText: ""),
                        );
                      }),
                    ),
                    Container(
                      margin: EdgeInsets.only(top: ScreenUtil().L(15), bottom: ScreenUtil().L(45)),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.end,
                        children: [
                          GFButton(
                            onPressed: () => controller.gotoForgetPwd(),
                            text: "忘记密码",
                            textStyle: KFontConstant.myTextStyle(size: 15, color: KColorConstant.black999999),
                            type: GFButtonType.transparent,
                          ),
                        ],
                      ),
                    ),
                    CupertinoButton(
                      onPressed: () => controller.login(),
                      child:Text("登录",style:  KFontConstant.myTextStyle(size: 17, color: KColorConstant.white)),
                      color: KColorConstant.btnColorF8633B,
                      borderRadius: BorderRadius.circular(ScreenUtil().L(5)),
                      padding: EdgeInsets.symmetric(horizontal: ScreenUtil().L(130)),
                    ),
                  ],
                ),
                Container(height: ScreenUtil().L(15)),
                Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    Obx(
                      () => GFCheckbox(
                        size: ScreenUtil().L(16),
                        activeBgColor: GFColors.SUCCESS,
                        inactiveBorderColor: KColorConstant.black999999,
                        type: GFCheckboxType.circle,
                        activeIcon: Image.asset("icons/icon_check_blue_two.png"),
                        onChanged: (value) {
                          controller.checkTap();
                        },
                        value: controller.checkBtn.value,
                      ),
                    ),
                    Container(
                      width: ScreenUtil().L(4),
                    ),
                    Text("已阅读并同意", style: KFontConstant.myTextStyle(size: 12, color: KColorConstant.black999999)),
                    InkWell(
                        child: Text("《用户服务协议》", style: KFontConstant.myTextStyle(size: 12, color: KColorConstant.blue3C5A99)),
                        onTap: () => controller.gotoUserAgreement()),
                    Text("和", style: KFontConstant.myTextStyle(size: 12, color: KColorConstant.black999999)),
                    InkWell(
                        child: Text("《隐私政策》", style: KFontConstant.myTextStyle(size: 12, color: KColorConstant.blue3C5A99)),
                        onTap: () => controller.gotoPrivacy()),
                  ],
                ),
                Container(height: ScreenUtil().L(130)),
                GFButton(
                    onPressed: () => controller.gotoForgetPwd(),
                    fullWidthButton: true,
                    type: GFButtonType.transparent,
                    size: GFSize.LARGE,
                    child: Text("本机号码一键登录", style: KFontConstant.myTextStyle(size: 15, color: Colors.blue, bold: true))),
              ])),
        ));
  }
}
